package com.dm0858.bianmin.mine.tools;

import android.graphics.Rect;
import android.util.DisplayMetrics;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

/**
 * @description 主要用于RecyclerView每个item的间隔设置
 * @author 迪迪丶Sir
 * @e-mail asd969709719@qq.com
 * @since 2020-03-25
 **/
public class ItemDecorationUtils extends RecyclerView.ItemDecoration {

    //分割线宽度
    private int left = 0;
    private int top = 0;
    private int right = 0;
    private int bottom = 0;

    //用于区分时那个recyclerView
    private int type = 0;
    //当前的位置
    private int position;
    //item的数量
    private int itemCount;
    //获取手机屏幕信息
    private DisplayMetrics metrics = new DisplayMetrics();


    //实际的px
    private int px;
    public ItemDecorationUtils(int left,int top,int right,int bottom,int type){
        this.left = ConversionUtils.dp2px(left);
        this.top = ConversionUtils.dp2px(top);
        this.right = ConversionUtils.dp2px(right);
        this.bottom = ConversionUtils.dp2px(bottom);
        this.type = type;
    }

    @Override
    public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
        super.getItemOffsets(outRect, view, parent, state);
        position = parent.getChildAdapterPosition(view);
        itemCount = parent.getAdapter().getItemCount();
        switch (type) {
            //默认
            case 0:
                outRect.left = left;
                outRect.top = top;
                outRect.right = right;
                outRect.bottom = bottom;
                break;
            case 1:
                //针对拼车首页快捷入口两列的列表
                if (position % 2 == 0) {
                    outRect.left = left;
                    outRect.right = right / 4;
                } else {
                    outRect.left = left / 4;
                    outRect.right = right;
                }
                outRect.top = top;
                outRect.bottom = bottom;
                break;
        }


    }

}
